// import {StrictMode} from 'react'
import {createRoot} from 'react-dom/client'
import AppProvider from "./sources/AppProvider.ts";
import {ThemeProvider} from "@mui/material";
import {createBrowserRouter, RouteObject, RouterProvider} from "react-router-dom";
import {LauncherRouteSoftware} from "./LauncherRouteSoftware.tsx";
import {Util} from "./sources/Util.ts";
import StartHomeAppView from "./application/_HomeApp/StartHomeAppView.tsx";
import ErrorView from "./framework/ErrorView.tsx";
// import HomeApp from "./application/_HomeApp/HomeApp.tsx";
import {LauncherRouteCore} from "./LauncherRouteCore.tsx";
import RecommendView from "./application/_HomeApp/views/RecommendView.tsx";
// import SearchView from "./application/_HomeApp/views/SearchView.tsx";
// import TabItemView from "./application/_HomeApp/views/TabItemView.tsx";
// import {useMemo} from "react";
import DGAccount from "./framework/DGAccount/DGAccount.tsx";

// 主题全局上下文
const AppThemeContext = AppProvider.AppThemeContext;
// 应用全局上下文
const AppContext = AppProvider.AppContext;

export const Launcher = () => {
    // // 生成动态路由信息
    // const DynamicRoutes = useMemo(() => {
    //     // 返回遍历
    //     return LauncherRouteSoftwareType.map((v1) => {
    //         let xxx = {};
    //         if (LauncherRouteSoftware.filter(item => item["type"] === v1['id']).length > 0) {
    //             xxx = {path: "item-" + v1['id'], element: <TabItemView id={v1['id']} title={v1['title']}/>}
    //         }
    //         return xxx;
    //     })
    // }, []);
    // 删除验证信息
    Util.Storage.delSession("FORGET-ACCOUNT");
    Util.Storage.delSession("FORGET-EMAIL");
    // 程序上下文提供器
    const AppContextProvider = AppProvider.AppContextProvider();
    // 主题上下文提供器
    const AppThemeContextProvider = AppProvider.AppThemeContextProvider();
    return (<>
        {/* 主题上下文提供器 */}
        <AppThemeContext.Provider value={AppThemeContextProvider.ThemeMethod}>
            {/* 主题切换提供器 */}
            <ThemeProvider theme={AppThemeContextProvider.ChangeThemeStyle}>
                {/* 全局上下文提供器 */}
                <AppContext.Provider value={AppContextProvider.AppMethod}>
                    <RouterProvider router={createBrowserRouter([
                        {
                            path: "/", element: <StartHomeAppView/>, errorElement: <ErrorView/>,
                            children: [
                                // 首页页面组件
                                {
                                    path: "/",
                                    element: <DGAccount/>,
                                    children: [{index: true, element: <RecommendView/>}]
                                },
                                // // 重定向首页页面组件为 index
                                // {
                                //     path: "index", element: <HomeApp/>, children: [
                                //         // 首页推荐页面组件
                                //         {index: true, element: <RecommendView/>},
                                //         // 首页搜索页面组件
                                //         {path: "search", element: <SearchView/>},
                                //         // 分类页面（动态路由）
                                //         ...DynamicRoutes
                                //     ] as RouteObject[],
                                // },
                                ...LauncherRouteCore
                            ] as RouteObject[]
                        },
                        ...LauncherRouteSoftware
                    ])}/>
                </AppContext.Provider>
            </ThemeProvider>
        </AppThemeContext.Provider>
    </>);
}

createRoot(document.getElementById('root')!).render(<Launcher/>)
